import pymysql
def main():
    no = int(input("请输入要更新的部门编号："))
    location = input("请输入部门地址：")
    conn = pymysql.connect(host='',port=3306,
                           user='root',password='admin@9000',
                           database='my_database',charset='utf8')
    try:
        with conn.cursor() as cursor:
            result = cursor.execute("update   tb_dept set location = %s   where deptno = %s",(location,no ))
            if result ==1:
                print("更新成功")
            conn.commit()
    except pymysql.MySQLError as error:
        print(error)
        conn.rollback()
    finally:
        conn.close()


    print(conn)
if __name__ == '__main__':
    main()